<template>
  <van-popup v-model="show" position="bottom" @click-overlay="clickOverlay">
    <van-datetime-picker
      v-model="currentDate"
      item-height="45"
      visible-item-count="4"
      :type="type"
      :title="title"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="clickOverlay"
    />
  </van-popup>
</template>

<script>
export default {
  name: 'DatetimeSelect',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      required: false,
      default: 'date'
    },
    title: {
      type: String,
      required: false,
      default: '请选择年月日'
    }
  },
  data() {
    return {
      minDate: new Date(1920, 0, 1),
      maxDate: new Date(2120, 11, 1),
      currentDate: new Date()
    }
  },
  computed: {},
  methods: {
    onConfirm() {
      this.$emit('onConfirm', this.currentDate)
    },
    clickOverlay() {
      this.$emit('clickOverlay')
    }
  }
}
</script>
